import 'dart:math';

import 'package:flutter/material.dart';
import 'package:bruno/bruno.dart';

import 'c-form.dart';

void main() {
  runApp(const MyApp());
}

class MyApp extends StatelessWidget {
  const MyApp({super.key});

  // This widget is the root of your application.
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'test',
      theme: ThemeData(
        primarySwatch: Colors.pink,
      ),
      home: const MyHomePage(title: 'Flutter Demo Home Page'),
    );
  }
}

class MyHomePage extends StatefulWidget {
  const MyHomePage({super.key, required this.title});
  final String title;

  @override
  State<MyHomePage> createState() => _MyHomePageState();
}

class _MyHomePageState extends State<MyHomePage> {
  String _counter = '0';
  TextEditingController userName = TextEditingController();
  TextEditingController passWord = TextEditingController();
  final _random = Random();
  // ignore: non_constant_identifier_names
  List<String> Arr = ['123', '6546', '888'];
  void _incrementCounter() {
    setState(() {
      _counter = Arr[_random.nextInt(Arr.length)];
    });
  }

  // ignore: non_constant_identifier_names
  Cform CformWt = Cform(
    list: [
      {
        'type': 'input',
        'name': '输入框',
        'field': 'input',
        'value': '1234',
        'callback': (e) {
          // 回调
          print(e);
        }
      },
      {
        'type': 'InputText',
        'field': 'InputText',
        'value': '64654',
        'name': '富文本',
        'callback': (e) {
          // 回调
          print(e);
        }
      },
      {
        'type': 'radio',
        'name': '单选框',
        'value': 'a1',
        'field': 'radio',
        'options': const [
          {'name': '单选1', 'value': 'a1'},
          {'name': '单选2', 'value': 'a2'},
        ],
        'callback': (e) {
          // 回调
          print(e);
        }
      },
    ],
  );

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text(widget.title),
      ),
      body: Center(
        child: Column(
          children: <Widget>[
            Center(
              child: BrnAddLabel(
                title: "登录",
                onTap: () {
                  CformWt.setData('radio', 'a2');
                  CformWt.setData('input', '1312313cdsxd');
                  // CformWt.setData('InputText', 'aass');
                },
              ),
            ),
            CformWt,
            // TextField(
            //   controller: userName,
            //   decoration: const InputDecoration(
            //     labelText: "用户名",
            //     hintText: "请输入用户名",
            //     prefixIcon: Icon(Icons.person),
            //   ),
            // ),
            // TextField(
            //   controller: passWord,
            //   decoration: const InputDecoration(
            //     labelText: "密码",
            //     hintText: "请输入密码",
            //     prefixIcon: Icon(Icons.person),
            //   ),
            // ),
            // MaterialButton(
            //   onPressed: () {
            //     BrnToast.show("请输入密码", context);
            //     print(userName.text);
            //     print(passWord.text);
            //   },
            //   textColor: Colors.pink,
            //   color: const Color.fromARGB(255, 3, 230, 135),
            //   child: const Text('登录'),
            // )
          ],
        ),
      ),
    );
  }
}
